home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4103 < prev    next >
Encoding:
Text File  |  1996-08-05  |  4.2 KB  |  148 lines

  1. Path: reno.WPI.EDU!vittohue
  2. From: Jose Andres Giraldez <vittohue@wpi.edu>
  3. Newsgroups: comp.lang.c
  4. Subject: Segmentation Error..Newbie needs help.
  5. Date: Thu, 1 Feb 1996 18:32:38 -0500
  6. Organization: Worcester Polytechnic Institute
  7. Message-ID: <Pine.OSF.3.91.960201182953.9997A-100000@reno.WPI.EDU>
  8. NNTP-Posting-Host: reno.wpi.edu
  9. Mime-Version: 1.0
  10. Content-Type: TEXT/PLAIN; charset=US-ASCII
  11.  
  12.  
  13. earlier today I finished my prog, then I decided to rewrite it in a more 
  14. modular fashion. I rewrote it as seen below. (I still have to rewrite the 
  15. plotting technique).
  16.  
  17. Please help me find the segemntation fault in this code:
  18.  
  19.  
  20. /*It works on BIGWPI.wpi.edu*/
  21.  
  22. #include <stdio.h>
  23. #include <float.h>
  24. #include <math.h>
  25. #include "/cs/cs1005/problems/problem2/test2.h"
  26.  
  27. int round (int);
  28.  
  29.  
  30. double conv_theta(double);
  31. double conv_radius(double);
  32. double sum_all_radi(double);
  33. double avg_radius(double);     
  34. double radius_derivations(double, double);
  35. double rads_to_degrees(double);     
  36.  
  37. /*int  count, counter, whole, n_rows, n_columns;
  38.   int j, value;
  39.   int graph;
  40.   float limit;
  41.   float temporary;
  42.   float Pi=3.14159;
  43.   float num;
  44.   float xval = limit;
  45.   double remainder;
  46.   double degrees[N_MEAS];
  47.   double min_rad_deri = 80.0;
  48.   double max_rad_deri = 0.0;
  49.   double derivation[N_MEAS];
  50.   double theta[N_MEAS];
  51.   double radius[N_MEAS];
  52.   double radius_sum;   This will find the sum of ALL the radius*/
  53.  
  54. /* main () is where all my results will be transfered to */
  55.  
  56. void main ()
  57. {  
  58.   int count;
  59.   double radius_A[N_MEAS];
  60.   double radius_B[N_MEAS];
  61.   double theta_A[N_MEAS];
  62.   double theta_B[N_MEAS];
  63.   double radius_sum;
  64.   double AvgRadius;
  65.   double derivation[N_MEAS];
  66.   
  67.   /*Find all values for the radius & theta conversions*/
  68.   for (count = 0; count < N_MEAS; count++){
  69.     
  70.     radius_B[count]=conv_radius( radius_A[count]); /*Put into Funct. #1*/
  71.     printf("This is radius: %lf",radius_B[count]); /*Shows results*/
  72.     
  73.     theta_B[count]=conv_theta( theta_A[count]);/*Put into Funct. #2*/ 
  74.     printf("THis is theta: %lf",theta_B[count]); /*Shows results*/
  75.   }
  76.   radius_sum=sum_all_radi(radius_B[count]); /*Put into Funct#3*/
  77.   printf("This is the sum af all radi: %lf",radius_sum); /*Shows results*/
  78.   
  79.   AvgRadius=avg_radius(radius_sum);/*Sets AvgRadius = ret funct#4*/
  80.   printf("THis is the Average radius: %lf",AvgRadius);/*Shows results*/
  81.   
  82.   derivation[count] = radius_derivations(AvgRadius, radius_B[count]);
  83.   printf("THese are the derivations: %lf\n",derivation[count]); 
  84. }  
  85.  
  86. /*FUNCTION #1*/
  87. /*************************************/
  88. double conv_radius(double radius_B) /*Funct. #1 Convert to Radius*/
  89. {
  90.   int count;
  91.   radius_B = sqrt((x[count] * x[count]) + (y[count] * y[count]));
  92.   /*Function above converts the (x,y) arrays into radi*/
  93.   return radius_B;
  94. }
  95.  
  96. /*FUNCTION #2*/
  97. /************************************/
  98. double conv_theta(double theta_B) /*Funct. #2 Convert to Theta*/
  99. {
  100.   int count;
  101.   theta_B= atan2(y[count], x[count]);
  102.   /*Function above convertss solves with math.h to get the radians*/
  103.   return theta_B;
  104. }
  105.  
  106. /*FUNCTION #3*/
  107. /**********************************/
  108. double sum_all_radi(double radius_B) /*Funct. #3 Adds to get radius_sum*/
  109. {
  110.   int count;
  111.   double radius_sum;
  112.   for (count =0; count <N_MEAS; count++){
  113.     radius_sum = radius_sum + radius_B;
  114.   }
  115.   return radius_sum;
  116.  
  117. /*FUNCTION #4*/
  118. /***********************************/
  119. double avg_radius(double radius_sum)/*Funct. #4 Calculates the avg. radius*/
  120. {
  121.   return (float) radius_sum / N_MEAS; /*Total sum is / by total size*/
  122. }
  123.  
  124. /*FUNCTIOn #5*/
  125. /***********************************/
  126. double radius_derivations(double derivation, double radius_B)
  127. {
  128.   int count;
  129.   double AvgRadius;
  130.   /*Find the deviations from the avg radius*/
  131.   for (count=0; count < N_MEAS; count++)
  132.     {
  133.       double derivation[count];
  134.       derivation[count] = (float) AvgRadius - radius_B;
  135.     }
  136.   
  137. }
  138.  
  139. /*Thanx*/
  140.  
  141. /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  142. --- Jose A. Giraldez "vittohueQwpi.edu"  Worcester Polytechnic Institute ---
  143. --- "I want to die quietly like my   |            EMSEP CLASS '99        ---
  144. --- Grandfather, not screaming like  |        Visual WEB. Programming    ---
  145. --- the people in his car."          |                SHPE & HSA            ---
  146. \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
  147.